#include<stdio.h>
int days(int year,int month);
int main()
{
	int year=0,month=0;
	int n=0;
	scanf("%d%d",&year,&month);
		if(year<=1000||year>=3000)
		{
			printf("invalid year!");
			return 0;
		}
		else if(month<1||month>12)
		{
			printf("invalid month!");
			return 0;
		}
		else if(year>1000&&year<3000&&month>=1&&month<=12)
		{
			n=days(year,month);
			printf("%d",n);
		}
	return 0;
}
int days(int year,int month)
{
	int day=0;
	switch (month){
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12: 
			day=31;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			day=30;
			break;
		case 2:
			if(year%4==0&&year%10!=0||year%400==0)
			{
				day=29;
			}
			else
			{
				day=28;
			}
			break;
	}
return day;

}
